﻿<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage<TireBias.Models.BIASPLANModel.BIASPLAN_DS>" %>

<script runat="server">

    protected void Page_Load(object sender, EventArgs e)
    {

    }
</script>
<asp:Content ID="Content1" ContentPlaceHolderID="TitleContent" runat="server">
   USE_KANBAN
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
    <div id="numericInput" style="float:left; width:300px;" >   
   <table id="keypad" class="hide">
         <tr style="background-color:#696969;"><td colspan="3" style="text-decoration:none; text-align:right;">
         <img src="<%: Url.Content("~/Images/power.png")%> "  alt='' width="100px" height="75px" id="close" />
         </td></tr>
         <tr class="rowa" >
            <td class="key cell">
               1
            </td>
            <td class="key cell">
               2
            </td>
            <td class="key cell">
               3
            </td>
         </tr>
         <tr class="rowa" >
            <td class="key cell">
               4
            </td>
            <td class="key cell">
               5
            </td>
            <td class="key cell">
               6
            </td>
         </tr>
         <tr class="rowa" >
            <td class="key cell">
               7
            </td>
            <td class="key cell">
               8
            </td>
            <td class="key cell">
               9
            </td>
         </tr>
         <tr class="rowa" >
            <td class="btn">
               DEL
            </td>
            <td class="key cell">
               0
            </td>
            <td class="key cell">
               .
            </td>
         </tr>
      </table>
</div>

   <table class="shadow" style=" width: 98%">
      <% if (WinNemoLib.StrUtil.IsNotEmpty(Model._Text))
         {%>
      <tr>
         <td class="cell" style="font-size: x-large;line-height: 30px; 
            padding: 5px; background-color: #C38DEC;color:White" colspan="3">
            <%= Model._Text%>
         </td>
      </tr>
      <%} %>
      <tr class="rowb">
         <td class="head cell text-right" style="padding: 10px 0px; width: 50%; vertical-align: top;">
            <table id="tbl1" width="98%">
               <tr class="rowa cell" id="rowh">
                  <td class="head" colspan="2">
                     USE PLY PLAN <span class="fontTh">ใช้แผนการตัดผ้าใบ</span>
                  </td>
               </tr>
               <tr class="rowb cell">
                  <td style="line-height: 40px!important; border: 1px solid #000; width: 40%">
                     PLY
                  </td>
                  <td style="line-height: 40px!important; border: 1px solid #000">
                     Actual
                  </td>
               </tr>
               <% if (WinNemoLib.StrUtil.IsNotEmpty(Model._P1))
                  { %>
               <tr class="rowa cell">
                  <td style="line-height: 40px!important; border: 1px solid #000; width: 40%">
                     P1
                  </td>
                  <td style="line-height: 40px!important; border: 1px solid #000" id="sumP1">
                     &nbsp;
                  </td>
               </tr>
               <%} %>
               <% if (WinNemoLib.StrUtil.IsNotEmpty(Model._P2))
                  { %><tr class="rowa cell">
               <td style="line-height: 40px!important; border: 1px solid #000; width: 40%">
                  P2
               </td>
               <td style="line-height: 40px!important; border: 1px solid #000" id="sumP2">
                  &nbsp;
               </td>
            </tr>
               <%} %>
               <% if (WinNemoLib.StrUtil.IsNotEmpty(Model._P3))
                  { %><tr class="rowa cell">
               <td style="line-height: 40px!important; border: 1px solid #000; width: 40%">
                  P3
               </td>
               <td style="line-height: 40px!important; border: 1px solid #000" id="sumP3">
                  &nbsp;
               </td>
            </tr>
               <%} %>
               <% if (WinNemoLib.StrUtil.IsNotEmpty(Model._P4))
                  { %><tr class="rowa cell">
               <td style="line-height: 40px!important; border: 1px solid #000; width: 40%">
                  P4
               </td>
               <td style="line-height: 40px!important; border: 1px solid #000" id="sumP4">
                  &nbsp;
               </td>
            </tr>
               <%} %>
               <tr class="rowa cell" style="background-color:#20B2AA">
               <td style="line-height: 40px!important; border: 1px solid #000; width: 40%">
                   TOTAL</td>
               <td style="line-height: 40px!important; border: 1px solid #000" id="total">
                   &nbsp;</td>
            </tr>
            </table>
            <br />
            <table id="tbl2" width="98%">
               <tr class="rowa cell">
                  <td class="head" colspan="2">
                     CHOOSE PLY PLAN <span class="fontTh">เลือกแผนการตัดผ้าใบ</span><input type="hidden" id="subItem"  />
                  </td>
               </tr>
               <tr style="text-align: center; font-size: 8em; font-weight: bolder;  line-height: 200px; ">
                  <td id="ply1" style="border:2px solid black !important;" >
                       &nbsp;
                     </td>
                  <td id="ply2" style="border:2px solid black !important;" >
                     &nbsp;
                  </td>
               </tr>
               <tr style="height:100px">
                  <td class="style1">&nbsp;</td><td class="style1">&nbsp;</td>
               </tr>
               <tr><td class="style1"> <input type="button" id="back" value="BACK" 
                       class="btnFooter"  style="height: 75px;  width: 350px;" /></td>
               <td class="style1"> <input id="next" type="button" value="RUN" class="btnFooter" 
                       style="height: 75px; width: 350px;" /></td>
               </tr>
            </table>
         </td>
         <td style="vertical-align:top;">
            <table width="100%" style="height:100%">
            <tr> 
<td class="col cell" style="padding: 10px 0px; width: 25%;">
DATE-SEQ
<span class="fontTh">ล็อตที่ผลิต</span>
</td>
<td class="cell" id="seqDT">
<h3><%= Model._Plandt %>-<%=Model._Itemno %></h3>  
</td>
</tr>
 <tr class="rowb">
         <td class="col cell" style="padding: 10px 0px; width: 25%;">
            SIZE
            <span class="fontTh">ขนาดผ้าใบ</span>
         </td>
         <td class="cell" id="Td1">
         <h3> <%= Model._Size %></h3>  
         </td>
      </tr>
      <tr class="rowb">
         <td class="col cell" style="padding: 10px 0px; width: 25%;">
            FORMING
           
            <span class="fontTh">เครื่องที่สร้าง</span>
         </td>
         <td class="cell" id="Td2">
        <h3>   <%= Model._Forming %></h3> 
         </td>
      </tr>
     
      <tr class="rowb">
         <td class="col cell" style="padding: 10px 0px; width: 25%;">
            Topped Cord
            
            <span class="fontTh">ผ้าใบ</span>
         </td>
         <td class="cell" id="Td7">
         <h3>  <%= Model._Topcrdcd%></h3> 
         </td>
      </tr>
      <tr class="rowb">
         <td class="col cell" style="padding: 10px 0px; width: 25%;">
            Tire Cord Lot
         
            <span class="fontTh">ผ้าใบ</span>
         </td>
         <td class="cell" id="Td8">
         <h3>  <%= Model._tcrdlot %></h3> 
         </td>
      </tr>
      <tr class="rowb">
         <td class="col cell" style="padding: 10px 0px; width: 25%;">
            Roll No
          
            <span class="fontTh">รถคันที่</span>
         </td>
         <td class="cell" id="Td9">
         <h3>  <%= Model._toproll %></h3> 
         </td>
      </tr>
      <tr class="rowb">
         <td class="col cell" style="padding: 10px 0px; width: 25%;">
           Expired date
       
            <span class="fontTh">วันหมดอายุ</span>
         </td>
         <td class="cell">
         <h3>  <%= Model._topexp %></h3> 
         </td>
      </tr>
      <tr class="rowb">
         <td class="col cell" style="padding: 10px 0px; width: 25%;">
         Length (M.)
            
            <span class="fontTh">ความยาว(เมตร)</span>
         </td>
         <td class="cell" >
         <h3>  <%= Model._toplen %></h3> 
         </td>
      </tr>
       <% if (WinNemoLib.StrUtil.IsNotEmpty(Model._P1))
         { %>
      <tr class="rowb">
         <td class="col cell" style="padding: 10px 0px; width: 25%;">
            P1
          
            <span class="fontTh">ความยาวผ้าใบชั้นที่ 1 (มม.)</span>
         </td>
         <td class="cell" id="Td3">
     <h3>  <%= Model._P1%></h3>     
         </td>
      </tr>
      <% } %>
      <% if (WinNemoLib.StrUtil.IsNotEmpty(Model._P2))
         { %>
      <tr class="rowb">
         <td class="col cell" style="padding: 10px 0px; width: 25%;">
            P2
            
            <span class="fontTh">ความยาวผ้าใบชั้นที่ 2 (มม.)</span>
         </td>
         <td class="cell" id="Td4">
        <h3>   <%= Model._P2%></h3> 
         </td>
      </tr>
      <% } %>
      <% if (WinNemoLib.StrUtil.IsNotEmpty(Model._P3))
         { %>
      <tr class="rowb">
         <td class="col cell" style="padding: 10px 0px; width: 25%;">
            P3
         
            <span class="fontTh">ความยาวผ้าใบชั้นที่ 3 (มม.)</span>
         </td>
         <td class="cell" id="Td5">
           <h3> <%= Model._P3%></h3>
         </td>
      </tr>
      <% } %>
      <% if (WinNemoLib.StrUtil.IsNotEmpty(Model._P4))
         { %>
      <tr class="rowb">
         <td class="col cell" style="padding: 10px 0px; width: 25%;">
            P4          
            <span class="fontTh">ความยาวผ้าใบชั้นที่ 4 (มม.)</span>
         </td>
         <td class="cell" id="Td6">
          <h3> <%= Model._P4%></h3> 
         </td>
      </tr>
      <% } %>


<tr class="rowb " id="trW1">
<td class="col cell" style="padding: 10px 0px; width: 25%; ">
   PLY1 Width <span class="fontTh">ความกว้าง</span></td>
<td class="cell" id="tdW1">
    &nbsp;</td>
</tr>

<tr class="rowb " id="trW2">
<td class="col cell" style="padding: 10px 0px; width: 25%; ">
   PLY2 Width <span class="fontTh">ความกว้าง</span></td>
<td class="cell" id="tdW2">
    &nbsp;</td>
</tr>
<tr class="rowb " id="wTotal">
<td class="col cell" style="padding: 10px 0px; width: 25%; ">
<span></span> Total Width (M.)         
<span class="fontTh">ความกว้างรวม (ม.)</span><span></span>
</td>
<td class="cell" id="wtotal">
&nbsp;</td>
</tr>
            </table>
            
            </td>
      </tr>
   </table>
</asp:Content>
<asp:Content ID="Content3" ContentPlaceHolderID="FeaturedContent" runat="server">
    <style type="text/css">
    #next
    {
        background-color:Red;
        color:Black;
        }
    #next:hover
    {
        color:White;
    }
.key
{
    border:1px solid #000000 !important;
}
#close:hover
{
    cursor:pointer;
    }
.cell
{
   line-height:35px !important;
 
}
.col
{ font-weight:bolder;
   padding: 5px 0px 5px 100px !important; 
   width: 50% !important; 
   text-align: left !important;
   background-color:#ccc !important;
}
   .style1
   {
      width: 49%;
   }
   .hide
   {
      display:none;
   }
        input[type="text"]
      {
         font-size: 1em;
         height: 2em;
         line-height: 2.5em;
         width: 90%;
      }
</style>
</asp:Content>
<asp:Content ID="Content4" ContentPlaceHolderID="TableContent" runat="server">
</asp:Content>
<asp:Content ID="Content5" ContentPlaceHolderID="ScriptsSection" runat="server">
    <% if (false)
   { %>
<script src="../../Scripts/jquery-1.7.1.js" type="text/javascript"></script>
<% } %>
<script type="text/javascript">
    $(function () {
        var $newPosX = 300;
        var $newPosY = 300;
        $("#numericInput").draggable({
            drop: function (event, ui) {

                // position of the draggable minus position of the droppable
                // relative to the document
                $newPosX = ui.offset.left - $(this).offset().left;
                $newPosY = ui.offset.top - $(this).offset().top;

            }
        });
        var clickNum;
        $('.key').click(function (event) {

            var numBox = clickNum;
            o = numBox.data('mask');

            var max = o.maxLength;

            if (numBox.val().length == max) {
                return;
            }

            var v = $.trim(this.innerHTML);
            var valueArray = ($.trim(numBox.val())).split('')
            var idx = $.inArray(".", valueArray);

            if ((v == ".") && (idx > -1)) {
                return;
            }

            if ($.trim(this.innerHTML) == ".") {
                if ($.inArray(".", o.maskArray) < 0) {
                    return;
                }
                numBox.val(numBox.val() + '.');
                return;
            }

            var i = valueArray.length;


            if (idx >= 0) {
                var pt = o.maskArray.length - ($.inArray(".", o.maskArray));
                var x = valueArray.length + 1 - idx;
                if (x > pt) {
                    return;
                }
                i = $.inArray(".", o.maskArray) + 1;


            } else if ((i > 0) && (o.maskArray[i] == '.')) {
                numBox.val(numBox.val() + '.');
            }

            if (o.maskNonFixedCharsArray[i] == 'undefine') {
                return;
            }
            if (v <= o.maskNonFixedCharsArray[i]) {
                numBox.val(numBox.val() + v);
            }

            event.stopPropagation();
        });

        $('.btn,#close').click(function (event) {
            var numBox = clickNum
            if ($.trim(this.innerHTML) == 'DEL') {
                if (numBox.val().length > 0) {
                    clickNum.val(numBox.val().substring(0, numBox.val().length - 1));
                }
                else {
                    numBox.val('');
                }
            }
            else {
                $("#keypad").slideToggle();
                clickNum = null;
            }
            event.stopPropagation();
        });


        $('.req').live("click", function (event) {
            var o = {
                left: $newPosX,
                top: $newPosY
            };

            if ((clickNum == null) || ($(this).attr("id") == clickNum.attr("id"))) $("#keypad").slideToggle().offset(o);
            clickNum = $(this);
            event.stopPropagation();
        });

        $.post('<%=Url.Action("Get_Value") %>' + '?seq=' + '<%= Model._Plandt %>' + "-" + '<%=Model._Itemno %>' + "&biasno=" + '<%: Model._Biasno %>' + "&shift=" + '<%: Model._Shift %>'
      , function (data) {
          if (data.success == 1) {
              $("#subItem").val(data.subItem);
              $("#ply1").text(data.ply1);
              $("#ply2").text(data.ply2);
              //     Get WidthTotal
              $.post('<%=Url.Action("GET_TireSTD") %>' + '?code=' + '<%= Model._Topcrdcd %>' + "&sizes=" + '<%: Model._Size %>' + "&forming=" + '<%: Model._Forming %>'
                , function (d) {
                    var total = 0;
                    for (i = 0; i < d.length; i++) {

                        if (data.ply1 == "P" + d[i]._Ply) {
                            total = total + parseFloat(d[i]._Width);
                            $("#tdW1").html("<h3>" + d[i]._Width + "</h3>");
                        }
                        if (data.ply2 == "P" + d[i]._Ply) {
                            total = total + parseFloat(d[i]._Width);
                            $("#tdW2").html("<h3>" + d[i]._Width + "</h3>");
                        }
                    }
                    if (total > 0) {
                        $("#wtotal").html("<h3>" + total.toString() + "</h3>");
                    }
                });

          }
          else alert(data.message);
      });

        $("#next").click(function () {
            NextPage();
        });



        var seq = '<%= Model._Plandt %>' + '-' + '<%= Model._Itemno %>';
        $.post('<%=Url.Action("GET_USE","BiasHead")%>' + '?seq=' + seq + '&biasno=' + '<%= Model._Biasno %>', function (data) {
            if (data.length > 0) {
                $("#sumP1").text(data[0]._P1);
                $("#sumP2").text(data[0]._P2);
                $("#sumP3").text(data[0]._P3);
                $("#sumP4").text(data[0]._P4);
                var total = parseFloat(data[0]._P1) + parseFloat(data[0]._P2) + parseFloat(data[0]._P3) + parseFloat(data[0]._P4);
                $("#total").text(total);

            }
        });

        function NextPage() {
            var dataForSubmit = new Array();
            dataForSubmit.push({
                _biasno: '<%:  TireBias.Models.SessionBag.Current.biasno %>',
                _plandt: '<%: Model._Plandt %>',
                _itemno: '<%: Model._Itemno %>',
                _sitemno: $("#subItem").val(),
                _empname: '<%: User.Identity.Name %>',
                _shift: '<%:  TireBias.Models.SessionBag.Current.shift  %>',
                _Ply1: "",
                _Ply2: ""
            });
            var getUsersUrl = '<%= Url.Action("Run_TireSTD") %>';
            callScriptMethod(getUsersUrl, { theData: dataForSubmit }, 'ADD');
        }

        $("#back").click(function () {
            var url = '<%= Url.Action("RollBack_Data","BiasHead_KANBAN") %>' + '?seq=' + '<%= Model._Plandt %>' + "-" + '<%=Model._Itemno %>' + "&biasno=" + '<%: Model._Biasno %>' + "&shift=" + '<%: Model._Shift %>' + "&subItem=" + $("#subItem").val();
            url = url + '&shift=' + '<%: TireBias.Models.SessionBag.Current.shift  %>'
            window.location = url;
        });

        function callScriptMethod(url, jsonObject, action, callback, async) {

            callback = callback || function () { };
            async = (async == null || async);

            $.ajax({
                type: "POST",
                contentType: "application/json; charset=utf-8",
                url: url,
                data: JSON.stringify(jsonObject),
                dataType: "json",
                async: async,
                success: function (data) {

                    if (data.success != "0") {
                        var getUsersUrl = '<%= Url.Action("GET_PDF_INF") %>' + '?seq=' + $.trim($("#seqDT").text()) + '&biasno=' + '<%: TireBias.Models.SessionBag.Current.biasno %>' + '&shift=' + '<%: Model._Shift %>' + "&subItem=" + $("#subItem").val();

                        window.location = getUsersUrl;
                    } else alert(data.message);
                },
                error: function (xhr, status, error) {
                    var err = xhr.responseText;
                    alert(err.Message);
                }
            });
        }

    });

</script>
</asp:Content>
